package com.shxzz.shortlink.admin.controller;

import com.shxzz.shortlink.admin.common.convention.result.Result;
import com.shxzz.shortlink.admin.common.convention.result.Results;
import com.shxzz.shortlink.admin.dto.req.GroupRegisterReqDTO;
import com.shxzz.shortlink.admin.dto.req.GroupSortReqDTO;
import com.shxzz.shortlink.admin.dto.req.GroupUpdateReqDTO;
import com.shxzz.shortlink.admin.dto.resp.GroupRespDTO;
import com.shxzz.shortlink.admin.service.GroupService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author shxzz
 * @create 2023-12-14-15:01
 * @description 短链接分组控制层
 */
@RestController
@RequiredArgsConstructor
public class GroupController {

    private final GroupService groupService;

    /**
     * 注册短链接分组
     */
    @PostMapping("/api/short-link/admin/v1/group")
    public Result<Void> register(@RequestBody GroupRegisterReqDTO requireParam) {
        groupService.register(requireParam);
        return Results.success();
    }

    /**
     * 查询短链接分组信息
     */
    @GetMapping("/api/short-link/admin/v1/group")
    public Result<List<GroupRespDTO>> findAllGroupInfo() {
        return Results.success(groupService.findAllGroupInfo());
    }

    /**
     * 短链接分组信息修改
     */
    @PutMapping("/api/short-link/admin/v1/group")
    public Result<Void> update(@RequestBody GroupUpdateReqDTO requireParam) {
        groupService.update(requireParam);
        return Results.success();
    }

    /**
     * 短链接分组删除
     * @param gid 短链接分组 组 ID
     */
    @DeleteMapping("/api/short-link/admin/v1/group")
    public Result<Void> deleteGroup(@RequestParam String gid) {
        groupService.deleteGroup(gid);
        return Results.success();
    }

    /**
     * 短链接分组排序设置
     * @param requestParam 短链接分组次序信息
     */
    @PostMapping("/api/short-link/admin/v1/group/sort")
    public Result<Void> sort(@RequestBody List<GroupSortReqDTO> requestParam) {
        groupService.sortGroup(requestParam);
        return Results.success();
    }
}
